找传奇、传世资源到传世资源站!

C# 桌面时钟(穿透)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

功能及说明:
1、开机自启动(如无效,请使用管理员模式运行)
2、横向和竖向显示
3、是否显示秒钟
4、是否显示背景
5、窗口置顶
6、任务栏透明
7、窗口是否鼠标穿透(取消穿透可以拖动窗口;双击窗口或通知栏图标会切换窗口穿透
8、窗口透明度
9、记录窗口位置(支持多屏) 10、修改窗口大小,有两个模式:自由拖动和滚动鼠标滚轮(都需在非鼠标穿透模式)且记录窗口大小 from clipboard
from clipboard

from clipboardC# 桌面时钟(穿透) C#语言基础-第4张 C# 桌面时钟(穿透) C#语言基础-第5张
using Startup;using System;using System.IO;using System.Runtime.InteropServices;using System.Windows;using System.Windows.Controls;using System.Windows.Forms;using System.Windows.Interop;using TaskbarsAlpha;using Orientation = System.Windows.Controls.Orientation;namespace Timer{ /// <summary> /// App.xaml 的交互逻辑 /// </summary> public partial class App : System.Windows.Application { public string inipath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase @"Setting.ini"; public System.Windows.Media.Brush Background; public MainWindow frm; private static NotifyIcon trayIcon; ///win32 api private const uint WS_EX_LAYERED = 0x80000; private const int WS_EX_TRANSPARENT = 0x20; private const int GWL_EXSTYLE = (-20); [DllImport("user32", EntryPoint = "SetWindowLong")] private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint dwNewLong); [DllImport("user32", EntryPoint = "GetWindowLong")] public static extern uint GetWindowLong(IntPtr hwnd, int nIndex); public ContextMenuStrip menu = new ContextMenuStrip(); public ToolStripMenuItem closeItem = new ToolStripMenuItem(); public ToolStripMenuItem topitem = new ToolStripMenuItem(); public ToolStripMenuItem shubiaoct = new ToolStripMenuItem(); public ToolStripMenuItem xuanzhuan = new ToolStripMenuItem(); public ToolStripMenuItem onlytxt = new ToolStripMenuItem(); public ToolStripMenuItem showss = new ToolStripMenuItem(); public ToolStripMenuItem taskbaralpha = new ToolStripMenuItem(); public ToolStripMenuItem startup_ = new ToolStripMenuItem(); public TrackBar tr = new TrackBar(); System.Threading.Mutex mutex; protected override void OnStartup(StartupEventArgs e) { LoadResourceDll.RegistDLL(); base.OnStartup(e); } private void ApplicationStartup(object sender, StartupEventArgs e) { mutex = new System.Threading.Mutex(true, "Timer"); if (!mutex.WaitOne(0, false)) { this.Shutdown(); } RemoveTrayIcon(); AddTrayIcon(); } public void AddTrayIcon() { if (trayIcon != null) { return; } trayIcon = new NotifyIcon { Icon = Timer.Properties.Resources.ico, Text = "时间" }; trayIcon.Visible = true; trayIcon.DoubleClick = TrayIcon_Click; menu.ShowCheckMargin = true; menu.Opened = Menu_Opened; menu.Closed = Menu_Closed; closeItem.Text = "退出"; closeItem.Click = new EventHandler(delegate { this.Shutdown(); }); closeItem.Image = Timer.Properties.Resources.exit; shubiaoct.Checked = true; shubiaoct.Text = "穿透"; shubiaoct.Click = new EventHandler(delegate { this.shubiao(); }); shubiaoct.Image = Timer.Properties.Resources.shubiao; topitem.Checked = true; topitem.Text = "置顶"; topitem.Click = new EventHandler(delegate { this.top(); }); topitem.Image = Timer.Properties.Resources.top; xuanzhuan.Text = "竖向"; xuanzhuan.Checked = true; xuanzhuan.Click = new EventHandler(delegate { this.xuanzh(); }); xuanzhuan.Image = Timer.Properties.Resources.change; onlytxt.Text = "背景"; onlytxt.Checked = true; onlytxt.Click = new EventHandler(delegate { this.onlyshowtxt(); }); onlytxt.Image = Timer.Properties.Resources.empty; showss.Checked = true; showss.Text = "秒钟"; showss.Click = new EventHandler(delegate { this.showss_(); }); showss.Image = Timer.Properties.Resources.ss; taskbaralpha.Checked = true; taskbaralpha.Text = "任务栏透明"; taskbaralpha.Click = new EventHandler(delegate { this.settaskbaralpha(); }); taskbaralpha.Image = Timer.Properties.Resources.tm; startup_.Checked = true; startup_.Text = "自启"; startup_.Click = new EventHandler(delegate { this.autorun_(); }); startup_.Image = Timer.Properties.Resources.autorun; tr.AutoSize = false; tr.Height = 22; tr.Maximum = 100; tr.Minimum = 0; tr.SmallChange = 5; tr.TickStyle = TickStyle.None; ToolStripControlHost tsc = new ToolStripControlHost(tr); menu.Items.Add(startup_); menu.Items.Add(xuanzhuan); menu.Items.Add(showss); menu.Items.Add(onlytxt); menu.Items.Add(topitem); menu.Items.Add(taskbaralpha); menu.Items.Add(shubiaoct); menu.Items.Add(tsc); menu.Items.Add(closeItem); tr.Scroll = new System.EventHandler(trackBar1_Scroll); trayIcon.ContextMenuStrip = menu; //设置NotifyIcon的右键弹出菜单 } public bool show = false; private void Menu_Closed(object sender, ToolStripDropDownClosedEventArgs e) { show = false; } private void Menu_Opened(object sender, EventArgs e) { show = true; } private void TrayIcon_Click(object sender, EventArgs e) { shubiao(); } public void autorun_() { startup_.Checked = !startup_.Checked; Startup_.InitializeOptions(startup_.Checked); saveinfo("_自启", startup_.Checked); } public void showss_() { (frm.images.Parent as DockPanel).Visibility = showss.Checked ? Visibility.Hidden : Visibility.Visible; showss.Checked = !showss.Checked; saveinfo("_秒钟", showss.Checked); } public void trackBar1_Scroll(object sender, EventArgs e) { MainWindow.Opacity = tr.Value / 100.00; shubiaoct.Text = "穿透(" (int)(MainWindow.Opacity * 100.00) "%)"; saveinfo("_透明度", tr.Value); } public void settaskbaralpha() { taskbaralpha.Checked = !taskbaralpha.Checked; TT.InitializeOptions(taskbaralpha.Checked); saveinfo("_任务栏透明", taskbaralpha.Checked); } public void onlyshowtxt() { (frm.imageh.Parent as DockPanel).Background = onlytxt.Checked ? null : Background; (frm.imagem.Parent as DockPanel).Background = onlytxt.Checked ? null : Background; (frm.images.Parent as DockPanel).Background = onlytxt.Checked ? null : Background; onlytxt.Checked = !onlytxt.Checked; saveinfo("_背景", onlytxt.Checked); } public void xuanzh() { xuanzhuan.Checked = !xuanzhuan.Checked; ChangeFX(); saveinfo("_竖向", xuanzhuan.Checked); } public void top() { MainWindow.Topmost = !MainWindow.Topmost; topitem.Checked = MainWindow.Topmost; saveinfo("_置顶", topitem.Checked); } public void shubiao() { shubiaoct.Checked = !shubiaoct.Checked; saveinfo("_穿透", shubiaoct.Checked); ct(); frm.ResizeMode = shubiaoct.Checked ? ResizeMode.NoResize : ResizeMode.CanResizeWithGrip; } public void ct() { bool f = shubiaoct.Checked; IntPtr hwnd = new WindowInteropHelper(MainWindow).Handle; if (!f) { SetWindowLong(hwnd, GWL_EXSTYLE, 0); } else { SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED); } } private void RemoveTrayIcon() { if (trayIcon != null) { trayIcon.Visible = false; trayIcon.Dispose(); trayIcon = null; } } private void ApplicationExit(object sender, ExitEventArgs e) { if (!mutex.WaitOne(0, false)) { return; } RemoveTrayIcon(); saveinfo(); } public void saveinfo() { var ini = new IniFile(); ini["_Setting"]["_自启"] = startup_.Checked; ini["_Setting"]["_竖向"] = xuanzhuan.Checked; ini["_Setting"]["_秒钟"] = showss.Checked; ini["_Setting"]["_背景"] = onlytxt.Checked; ini["_Setting"]["_置顶"] = topitem.Checked; ini["_Setting"]["_任务栏透明"] = taskbaralpha.Checked; ini["_Setting"]["_穿透"] = shubiaoct.Checked; ini["_Setting"]["_透明度"] = tr.Value; if (frm != null) { ini["_Setting"]["X"] = frm.Left; ini["_Setting"]["Y"] = frm.Top; ini["_Setting"]["W"] = frm.Width; ini["_Setting"]["H"] = frm.Height; } ini.Save(inipath); } public void saveinfo(string key, double value) { var ini = new IniFile(); if (File.Exists(inipath)) ini.Load(inipath); ini["_Setting"][key] = value; ini.Save(inipath); } public void saveinfo(string key, bool value) { var ini = new IniFile(); if (File.Exists(inipath)) ini.Load(inipath); ini["_Setting"][key] = value; ini.Save(inipath); } private void ChangeFX() { double tmp = MainWindow.Height; MainWindow.Height = MainWindow.Width; MainWindow.Width = tmp; frm.wrappanel1.Orientation = frm.wrappanel1.Orientation == Orientation.Horizontal ? Orientation.Vertical : Orientation.Horizontal; } public void ChangeSize(bool flag) { double diameter = 0.90; if (flag) diameter = 1.10; frm.Width = frm.Width * diameter; frm.Height = frm.Height * diameter; } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复